package algorithm.unionfind;

public class UnionFind1 extends AbstractUnionFind{



    public UnionFind1(int capacity){
        super(capacity);
    }



    @Override
    public int find(int p){
        return data[p];
    }

    @Override
    public void union(int p,int q){
        Integer pRoot = data[p];
        Integer qRoot = data[q];
        if (pRoot.equals(qRoot)){
            return;
        }

        //遍历数组中值为pRoot的元素，指向qRoot
        for (int i = 0; i < data.length; i++) {
            if (data[i]==pRoot){
                data[i] = qRoot;
            }
        }
    }
}
